import numpy as np
import cv2
from matplotlib import pyplot as plt
img1 = cv2.imread('E:\\5.jpg',0) # queryImage
img2 = cv2.imread('E:\\6.jpg',0) # trainImage
#print(img1)
# Initiate SIFT detector
orb=cv2.ORB_create(500)
# find the keypoints and descriptors with SIFT
kp1, des1 = orb.detectAndCompute(img1,None)
kp2, des2 = orb.detectAndCompute(img2,None)

kp1,des1 = cv2.cornerHarris(img1,2,3,0.04)
# create BFMatcher object
bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
# Match descriptors.
matches = bf.match(des1,des2)
# Sort them in the order of their distance.
matches = sorted(matches, key = lambda x:x.distance)
img3 = cv2.drawMatches(img1,kp1,img2,kp2,matches[100:-100], None,flags=2)
img4 = cv2.drawMatches(img1,kp1,img2,kp2,matches[0:20], None,flags=2)
#print(img3)
cv2.imshow('result',img4)
#cv2.imshow('result1',img4)
cv2.waitKey(0)
cv2.destroyAllWindows()